package com.example.test4.com.it.controller;

import com.example.test4.com.it.Service.ICompanyService;
import com.example.test4.com.it.domain.Company;
import com.example.test4.com.it.query.CompanyQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName CompanyController
 * Descrition TD00
 * Author Zhang Hai Xia
 * date 2021/10/23 16:53
 * @Version 1.0
 */
@RestController
public class CompanyController {


    @Autowired
    ICompanyService companyService;


    @GetMapping("/findAll")
    public Map<String, Object> findAll() {
        Map<String, Object> map = new HashMap<>();
        List<Company> list= companyService.findAll();

        map.put("list",list);
        return map;
    }

    @GetMapping("/delete")
    public Map<String, Object> delete(Integer id){
        Map<String, Object> map = new HashMap<>();
        map.put("id"+id+"的值",companyService.findOne(id));
        companyService.delete(id);
        map.put("结束","删除id="+id+"的数据成功");
        return map;
    }


    @GetMapping("/getCompanyBy")
    public Object getCompanyBy(String companyName,String addrress,String chairman){
        CompanyQuery query = new CompanyQuery();
        query.setCurrentPage(1);
        query.setPageSize(30);
        query.setCompanyName(companyName);
        query.setAddrress(addrress);
        query.setChairman(chairman);

        List<Company> list = companyService.findBy(query);
        return list;
    }

    @GetMapping("/redis")
    public Object redis(String key){
        // 从redis中获取值
        String value = "hello";
        return "Redis中的"+key+"="+value;
    }
}
